/**
 * f1custom.java
 */

import com.renesys.raceway.views.*;

import java.awt.*;
import java.text.*;
import javax.swing.*;



public class f1custom {

    public static void main(String[] argv) {

	try {
	    //---------------------------------------------------------
	    //  1.  Create a new instance of the Raceway framework.
	    
	    final Raceway raceway = Raceway.create();
	    
	    //---------------------------------------------------------
	    //  2.  Load the view database. 
	    
	    raceway.loadView(argv);
	    
	    //---------------------------------------------------------
	    //  3.  Create a new stream, and add an interesting 
	    //      animation player to it. 
	    
	    final Stream f1 = raceway.loadStream("f1.dat.0");
	    
	    f1.addPlayer(new Stream.Player() {
		    public AttributedString describe(Stream.Record r) {
			return null;
		    }
		    public void play(Stream.Record r) {
			String rty = 
			    f1.getRecordTypeString(r.type_code);
			String nhi = 
			    f1.getRecordSourceString(r.source_code);
			if (rty.equals("SSF.OS.BGP4")) {
			    switch((int)r.bytes[r.offset]) {
			    case SSF.OS.BGP4.Monitor.CPU_BUSY:
				Raceway.VisibleHost host = 
				    raceway.getVisibleHost(nhi);
				System.err.println("SIMPLE PLAYER : "+
						   r+","+nhi+","+
						   (null==host?"null":
						    host.toString()));
				if (null==host) return;
				if (0==r.bytes[r.offset+1]){
                                    host.setFillColor(Color.red);
                                  //host.scaleSize(0.5);
				    host.refresh();
				} else {
                                    host.setFillColor(Color.blue);
                                  //host.scaleSize(2.0);
				    host.refresh();
				}
			    default:
				// ignore other records 
				break;
			    }
			}
		    }
		});
	    
	    //---------------------------------------------------------
	    //  4.  Create a Net viewer, a DML viewer, and a Stream 
	    //      viewer, and combine into a couple of split panels. 
	    
	    JSplitPane split_1 = 
		new JSplitPane(JSplitPane.VERTICAL_SPLIT,
			       raceway.getNetViewer(),
			       raceway.getDMLViewer());
	    
	    JSplitPane split_2 = 
		new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
			       split_1,
			       raceway.getStreamViewer(f1));
	    
	    
	    //---------------------------------------------------------
	    //  5.  Launch a frame to contain everything. 
	    
	    final JFrame frame = new JFrame();
	    frame.getContentPane().add(split_2);
	    frame.setSize(640,480);
	    frame.show();
	    
	    split_2.setDividerLocation(0.5);
	    split_1.setDividerLocation(0.5);

	}  catch (java.io.IOException ioex) {
	    ioex.printStackTrace();
	    System.exit(-1);
	}
    }

}
